package com.oitsm.mo.action;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.oitsm.commons.action.BaseAction;
import com.oitsm.mo.cache.NodeCache;
import com.oitsm.mo.entity.Node;
import com.oitsm.utils.JSONUtils;
/**
 * MO 缓存Action
 * @author Arab Runner
 * Jun 25, 2011 11:53:25 AM
 */
public class MOCacheAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 获取节点信息
	 * @return
	 * @throws Exception
	 */
	public String getNodes()throws Exception{
		Long id = null;
		try{
			id = Long.parseLong(this.getRequest().getParameter("node"));
		}catch(Exception e){
		}
		
		List<Node> nodes = NodeCache.getChildrenNodes(id);
		JSONArray ja = new JSONArray();
		for(Node n : nodes){
			JSONObject jo = new JSONObject();
			jo.put("text", n.getName());
			jo.put("id", n.getId());
			jo.put("type", n.getType());
			jo.put("leaf", !NodeCache.hasChildren(n.getId()));
			ja.add(jo);
		}
		JSONUtils.write(this.getResponse(), ja.toString());
		return null;
	}
}
